package org.example.command;

import org.example.model.HTMLDocument;
import org.example.service.tree.VisualTreeViewer;
import org.example.service.tree.impl.HtmlNameProvider;
import org.example.service.tree.impl.HtmlTreeContentProvider;
import org.jsoup.nodes.Node;

public class PrintTreeCommand implements Command {
    private HTMLDocument htmlDocument;

    public PrintTreeCommand(HTMLDocument htmlDocument) {
        this.htmlDocument = htmlDocument;
    }

    public static Command create(HTMLDocument htmlDocument){
        return new PrintTreeCommand(htmlDocument);
    }

    @Override
    public boolean execute() {
        printTree();  // 调用 HTMLDocument 中的 printTree 方法
        return true;
    }

    private void printTree(){
        VisualTreeViewer<Node> treeViewer = new VisualTreeViewer<>(new HtmlTreeContentProvider(htmlDocument.getDocument()), new HtmlNameProvider());
        treeViewer.show();
    }

}
